//
//  CashViewController.m
//  LiquorChain
//
//  Created by apple on 2019/1/5.
//  Copyright © 2019年 王冬. All rights reserved.
//

#import "CashViewController.h"
#import "CashViewCell.h"
#import "CashdrawalController.h"
@interface CashViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UITableView *tableView;
@end

@implementation CashViewController

static NSString *CellIdentifier = @"cashCell";
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我的现金";
    
    self.view.backgroundColor =[UIColor whiteColor];
    self.tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, kNavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT - kNavBarHeight- kIPhoneXBottomHeight) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
     //[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
    [self.tableView registerNib:[UINib nibWithNibName:@"CashViewCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
    [self.view addSubview:self.tableView];
    
    [self creatHeadView];
    // Do any additional setup after loading the view.
}

-(void)creatHeadView{
    UIView *headView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 220)];
    headView.backgroundColor =[UIColor whiteColor];
    UIView *topView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 110)];
    topView.backgroundColor = CUSTOMCOLOR;
    UILabel *showLabel =[[UILabel alloc]init];
    [topView addSubview:showLabel];
    showLabel.text = @"账户余额(元)";
    showLabel.textColor = [UIColor whiteColor];
    showLabel.font =[UIFont systemFontOfSize:12];
    [showLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(21);
        make.left.mas_equalTo(14);
        make.height.mas_equalTo(12);
    }];
    //
    UILabel *showNumber =[[UILabel alloc]init];
    [topView addSubview:showNumber];
    showNumber.textColor =[UIColor whiteColor];
    showNumber.text =@"0.00001";
    showNumber.font = [UIFont systemFontOfSize:30];
    [showNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(14);
        make.top.mas_equalTo(40);
        make.height.mas_equalTo(23);
    }];
        // 昨日圣酒
        UILabel *oldLabel =[[UILabel alloc]init];
        [topView addSubview:oldLabel];
        oldLabel.textColor = [UIColor whiteColor];
        oldLabel.font = [UIFont systemFontOfSize:12];
        oldLabel.text = [NSString stringWithFormat:@"预期收益: ￥%f",0.12];
        [oldLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left .mas_equalTo(14);
            make.top.mas_equalTo(showNumber.mas_bottom).with.offset(15);
            make.height.mas_equalTo(12);
        }];
   
   
    
    
    
    UIButton *rightBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [topView addSubview:rightBtn];
    [rightBtn setBackgroundColor:[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:0.3]];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(40);
        make.right.mas_equalTo(-16);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(30);
    }];
    rightBtn.layer.cornerRadius = 15;
    [rightBtn setTitle:@"现金来源" forState:UIControlStateNormal];
    [rightBtn setImage:[UIImage imageNamed:@"rightj"] forState:UIControlStateNormal];
    [rightBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:4];
    [rightBtn setTitleColor:[UIColor whiteColor]
                   forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightClick:) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:topView];
    
    
    UIButton *cashtiBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [headView addSubview:cashtiBtn];
    cashtiBtn.backgroundColor =CUSTOMCOLOR;
    [cashtiBtn setTitle:@"提现" forState:UIControlStateNormal];
    [cashtiBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cashtiBtn addTarget:self action:@selector(cashClick:) forControlEvents:UIControlEventTouchUpInside];
    [cashtiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
        make.top.mas_equalTo(topView.mas_bottom).with.offset(0.5);
    }];
    
    
    // 收支明细
    UILabel *pubGLabel =[[UILabel alloc]init];
    [headView addSubview:pubGLabel];
    pubGLabel.font = [UIFont systemFontOfSize:15];
    pubGLabel.text = @"收支明细";
    [pubGLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left .mas_equalTo(15);
        make.top.mas_equalTo(cashtiBtn.mas_bottom).with.offset(30);
        make.height.mas_equalTo(15);
    }];
    
    UILabel *pubGLabline =[[UILabel alloc]init];
    [headView addSubview:pubGLabline];
    pubGLabline.backgroundColor =[UIColor blackColor];
    [pubGLabline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left .mas_equalTo(15);
        make.top.mas_equalTo(pubGLabel.mas_bottom).with.offset(15);
        make.height.mas_equalTo(2);
        make.width.mas_equalTo(30);
    }];
    self.tableView.tableHeaderView = headView;
}
-(void)cashClick:(UIButton *)sender{
    CashdrawalController *cashVC =[[CashdrawalController alloc]init];
    [self.navigationController pushViewController:cashVC animated:YES];
}
-(void)rightClick:(UIButton *)sender{
    NSLog(@"公益池来源");
    //创建控制器
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"现金来源" message:
                                  @"                                                                   推荐奖励：推荐朋友买酒，获得朋友买酒成交景丹师傅金额x10%的现金奖励；推荐买酒奖励到账时间以确认收货为准，名额不限，多推多得。\n 圣酒分红：根据自己持有圣酒数量，圣酒分红金额将记录在现金余额。\n注：未成为大师时收益记入预期收益，成为后即可提现。                                                       " preferredStyle:UIAlertControllerStyleAlert];
    //创建添加按钮（可以写事件，也可以不写），可以创建多个按钮
    UIAlertAction *OKbtn = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    }];
    
    //修改message
    //设置行间距
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.alignment = NSTextAlignmentLeft;
    paragraphStyle.lineSpacing = 10;//行间距
    
    
    NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:12], NSParagraphStyleAttributeName:paragraphStyle};//字体大小 行间距  颜色
    [alertVC setValue: [[NSAttributedString alloc]initWithString:alertVC.message attributes:attributes] forKey:@"attributedMessage"];
    
    
    //backImage
    UIImage *accessoryImage = [UIImage imageNamed:@"backImage1"];
    accessoryImage = [accessoryImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [OKbtn setValue:accessoryImage forKey:@"image"];
    [OKbtn setValue:[UIColor whiteColor] forKey:@"_titleTextColor"];

    //添加按钮到alertVC上，并模态出来
    [alertVC addAction:OKbtn];
    [self presentViewController:alertVC animated:YES completion:nil];
    
}

#pragma mark
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 65;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CashViewCell *cell =[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%ld",indexPath.row);
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
